import request from '@/utils/request'

export function getConfigList(data) {
    return request({
        url: '/hosts/config/list',
        method: 'get',
        params: data
    })
}

export function getconfigChangeLog(data) {
    return request({
        url: '/hosts/config/changelog',
        method: 'get',
        params: data
    })
}

export function getcveHosts({page, perPage, paged, search, sortBy, sortOrder, ...data}) {
    let params = {page, perPage, paged, search, sortBy, sortOrder};
    let url = "";
    data.cve.forEach((item) => {
        url = url + (url ? "&cveIds="+item : "cveIds="+item);
    })
    return request({
        url: '/hosts/list/filter/cve_fixed?' + url,
        method: 'get',
        params
    })
}

export function getPackageList(data) {
    return request({
        url: '/packagerecords/records',
        method: 'get',
        params: data
    })
}

export function getPackageHosts({page, perPage, paged, search, sortBy, sortOrder, ...data}) {
    let params = {page, perPage, paged, search, sortBy, sortOrder,};
    if (data.pack) {
        params["name"] = data.pack;
    }
    if (data.rule) {
        params["compare"] = data.rule;
    }
    if (data.version) {
        params["version"] = data.version;
    }
    return request({
        url: '/packagerecords/hostList',
        method: 'get',
        params
    })
}

export function getPackageChangeHosts({page, perPage, search, sortBy, sortOrder, ...data}) {
    let params = {page, perPage, search, sortBy, sortOrder,}
    if (data.pack) {
        params["name"] = data.pack
    }
    return request({
        url: '/packagerecords/hostchangeList',
        method: 'get',
        params
    })
}

export function getPackageChange(data) {
    return request({
        url: '/packagerecords/recordChange',
        method: 'get',
        params: data
    })
}

export function getPackageNames() {
    return request({
        url: '/packagerecords/name',
        method: 'get'
    })
}

export function getPackageVersion(data) {
    return request({
        url: '/packagerecords/version',
        method: 'get',
        params: data
    })
}